<?php

$thisModule = "habroad";
$activeSearchTab = "habroad";

addDataservice("getcompanieslike");
addDataService("getcountries");

loadJQueryPlugin("innerfade");
loadJQueryPlugin("freetextsearch");
loadJQueryPlugin("submitter");

function buildLayout(&$smarty) {
    $smarty->assign("defaulttext", "Search for Hungarian companies all over the world");
    $smarty->assign("newwindow", true);
    $smarty->assign("searchcontent", getSearchScreen());
    $smarty->assign("activesearchtab", getActiveSearchTab());
    $smarty->assign("virt_exhibition", true);
    $smarty->assign("virt_exhibition_lang", "english");
    initDatabase();
    Database::loadModel("textcomments");
    $comments = Database::getAll();
    shuffle($comments);
    if (count($comments) > 0) {
        $smarty->assign("needcomments", true);
        $smarty->assign("comments", $comments);
    }
    Database::loadModel("companies");
    $companies = Database::getModel()->getRotatorCompaniesFor("ha");
    $pictures = array(
        array(src => "site/layout/searchscreen/resources/img/agendarium_logo.png", href => "http://www.lancasterconsulting.hu"),
        array(src => "site/layout/searchscreen/resources/img/youcv_banner_2.jpg", href => "http://www.lancasterconsulting.hu"),
        array(src => "site/layout/searchscreen/resources/img/budapest_banner.jpg", href => "http://www.exporthungary.hu"),
        array(src => "site/layout/searchscreen/resources/img/lancasterconsulting_banner.png", href => "http://www.lancasterconsulting.hu"),
    );
    $counter = 0;
    for ($i = 0; $i < count($companies) && $i < 4; $i++) {
        if ($i == 1) { $counter++; }
        $pictures[$counter]['src'] = callFileloaderDisplayCompanyFile("export", "rotator", $companies[$i]['company_id']);
        $pictures[$counter]['href'] = $companies[$i]['hphungarian'];
        $counter++;
        if ($counter >= 4) { break; }
    }
    $smarty->assign("pictures", $pictures);
}

function executeService($serviceName, $params) {
    switch ($serviceName) {
        case "getcompanieslike" : { return service_getcompanieslike($params); break; }
        case "getcountries" : { return service_getcountries($params); break; }
    }
}

function service_getcompanieslike($params) {
    $result = array();
    Database::loadModel("companies");
    $result = Database::getModel()->getHACompaniesLike($params['searchtext'], $params['dependant']);
    return serviceSuccessful(array(
        items => $result,
    ));
}

function service_getcountries($params) {
    Database::loadModel("companies");
    $result = Database::getModel()->getCountriesForCompanies();
    return serviceSuccessful(array(
        items => $result
    ));
}

function getPageHeader() {
    return TemplateHelper::getDefaultPageHeader();
}

function getPageFooter() {
    return TemplateHelper::getDefaultPageFooter();
}

function getSearchScreen() {
    global $smarty;
    global $thisModule;

    $templateFile = TemplateHelper::getTemplateFile($thisModule, "ha_search");
    return $smarty->fetch($templateFile);
}

function getActiveSearchTab() {
    global $activeSearchTab;
    
    return $activeSearchTab;
}

?>
